package com.zsr.controller;

import com.zsr.dao.FeedbackMapper;
import com.zsr.pojo.AnwersVo;
import com.zsr.pojo.ChoiceQuestionVo;
import com.zsr.pojo.Feedback;
import com.zsr.pojo.QuestionOneVo;
import com.zsr.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * @Author zsr
 * @Desc
 * @Date 2021/5/6 13:10
 */
@Controller
public class EnglishController {
    @Autowired
    @Qualifier("feedbackServiceImpl")
    private FeedbackService feedbackService;

    @PostMapping("/q10")
    @ResponseBody
    public List<ChoiceQuestionVo> test10() {
        String[] questionArr = {
                "（     ） refers to the processes that are used to acquire, store, retain, and later retrieve information."
                ,"An （      ） is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together."
                ," A（    ）is a memorized secret, typically a string of characters, usually used to confirm a user's identity."
                ,"(    )  statement can perform a calculation and store the result in a variable so that it can be used later."
                ,"（    ）is the most basic building block of the Web. It defines the meaning and structure of web content. "

                ,"In computing, （    ）is a set of data processing elements connected in series, where the output of one element is the input of the next one."
                ,"Every valid character in a computer that uses even (    ) must always have an even number of 1 bits."
                ,"(    ) is a set of specifications and software that allow small programs or software components to work together."
                ,"It increase “programs” (     ) and make them easier to maintain that use a standard indention technique, blank lines, form feeds, and spaces."
                ,"（   ） is the co-founder and former executive chairman of Alibaba Group, a multinational technology conglomerate."

                ,"The basic units of a computer system are as follows:（    ）"
                ,"Which one is not peripheral device?（    ）"
                ,"(    ) is used to communicate with another computer over telephone lines."
                ,"The TCP/IP model has (    ) layers."
                ,"Arrange in ascending order the units of memory TB, KB, GB, MB.（     ）"

                ,"MS-Excel is an example of （     ）."
                ,"Virus is a (     )."
                ,"（     ） is a device that enables the computer to handle sounds."
                ,"Information（    ）means protecting information and information systems from unauthorized access, use, disclosure, disruption, modification, or destruction. "
                ,"What cannot an operating system do? (     )"


        };
        String[] Anwers={
                "memory-storage-network-processor"
                ,"a line-a stack-an array-a queue"
                ,"name-password-device-computer"
                ,"Assignment-Control-Declaration-I/O"
                ,"URL-TCP/IP-HTML-WWW"

                ,"pipeline-sequence-execution-decode"
                ,"check-parity-test-compare"
                ,"ActiveX-XML-HTML-DBMS"
                ,"reliability-security-readability-usability"
                ,"Job Steven-Jack Ma-Bill Gates-Jeff Bezos"

                ,"CPU, memory and disk-CPU, input and output unit-CPU, memory and I/O system-CPU, memory and ALU "
                ,"RAM-mouse-monitor-scanner"
                ,"keyboard-modem-mouse-printer"
                ,"four-five-six-seven"
                ,"TB>MB>GB>KB-MB>GB>TB>KB-TB>GB>MB>KB-GB>MB>KB>TB"

                ,"An operating system-A processing device-Application software-An input device"
                ,"program-computer-bad man-beast"
                ,"Network card-Video card-Sound card-Monitor"
                ,"Integrity-availability-security-consistency"
                ,"It manages the hardware.-It manages the software.-It distributes the resources.-It acts as the CPU of the computers."

        };

        Integer[] TrueAnwersKeys = {
                1
                ,3
                ,2
                ,1
                ,3

                ,2
                ,2
                ,1
                ,3
                ,2

                ,3
                ,1
                ,2
                ,2
                ,3

                ,3
                ,1
                ,3
                ,3
                ,4
        };
        String[] TrueAnwers = {
                "1.Mmeory"
                ,"2.Arry"
                ,"3.Paasword"
                ,"4.Assignment"
                ,"5.Html"
                ,"6.sequence"
                ,"7.parity"
                ,"8.ActiveX"
                ,"9.readability"
                ,"10.Jack Ma"
                ,"11.cpu,memory and i/o system"
                ,"12.RAM"
                ,"13.modem"
                ,"14.five"
                ,"15.tb>gb>mb>kb"
                ,"16.application software"
                ,"17.program"
                ,"18.Sound card"
                ,"19.security"
                ,"20.it acts as the (d)"
        };
        List<ChoiceQuestionVo> result = new ArrayList<>();
        Map<Integer, String> tempMap;
        String[] split;
        List<AnwersVo> anwersVos;
        for (int i = 0; i < questionArr.length; i++) {
            anwersVos=new ArrayList<>();
            split= Anwers[i].split("-");
            for(int j=0;j<4;j++){
                anwersVos.add(new AnwersVo(j+1,split[j]));
            }
            Collections.shuffle(anwersVos); //随机打乱
            result.add(new ChoiceQuestionVo(
                    i, questionArr[i], anwersVos, TrueAnwersKeys[i], TrueAnwers[i]
            ));
        }
        Collections.shuffle(result); //随机打乱
        return result;
    }

    @PostMapping("/q1")
    @ResponseBody
    public List<QuestionOneVo> test1(int type) {
        String[] questionArr = {"scheme  n.", "workstation  n.", "float  v."
                , "monitor  n.", "template  n.", "allocate  vt.", "arrangement  n.", "bridge  n."
                , "category  n.", "concentrator  n.", "contrast  n.", "customize  v.", "defense  n."
                , "digital  adj.", "effect  n.", "embed  vt.", "erase  vt.", "feasible  adj."
                , "firewall  n.", "hypermedia  n."};
        String[] answerArr = {"方案", "工作站", "浮动"
                , "显示器", "模板", "分配", "排列", "网桥"
                , "类别", "集线器", "对比", "定制", "防御"
                , "数字的", "影响", "嵌入", "删除", "可行的"
                , "防火墙", "超媒体"};
        List<QuestionOneVo> result = new ArrayList<>();
        for (int i = 0; i < questionArr.length; i++) {
            result.add(new QuestionOneVo(
                    i, questionArr[i], answerArr[i], null
            ));
        }

        Collections.shuffle(result); //随机打乱
        return result;
    }

    @PostMapping("/q2")
    @ResponseBody
    public List<QuestionOneVo> test2() {
        String[] questionArr = {"n.体系结构", "vi.运行,行为", "n.部件"
                , "n.装备；设备 ", "vt.装载, 装入", "vt.建立", "v.打印", "vt.宣布, 通告"
                , "vt.估计，评定", "n.位图", "n.字符", "vt.汇编；编辑", "n.指针，光标"
                , "v.删除", "vt.放弃", "n.区别", "n.电子的", "n.均衡, 平衡"
                , "n.表示", "n.网络集线器"};
        String[] answerArr = {"architecture", "behave", "component"
                , "device", "load", "create", "print", "announce"
                , "assess", "bitmap", "character", "compile", "cursor"
                , "delete", "discard", "distinction", "electronic", "equilibrium"
                , "express", "hub"};
        List<QuestionOneVo> result = new ArrayList<>();
        for (int i = 0; i < questionArr.length; i++) {
            result.add(new QuestionOneVo(
                    i, questionArr[i], answerArr[i], null
            ));
        }

        Collections.shuffle(result); //随机打乱
        return result;
    }

    @PostMapping("/q3")
    @ResponseBody
    public List<QuestionOneVo> test3() {
        String[] questionArr = {"binary data", "bubble jet", "by default"
                , "case sensitive", "chip set", "dialogue box", "expansion card", "floppy disk"
                , "hard copy", "laser printer"};
        String[] answerArr = {"二进制数据", "喷墨", "默认情况下"
                , "区分大小写", "芯片组", "对话框", "扩展卡", "软盘"
                , "硬拷贝", "激光打印机"};
        List<QuestionOneVo> result = new ArrayList<>();
        for (int i = 0; i < questionArr.length; i++) {
            result.add(new QuestionOneVo(
                    i, questionArr[i], answerArr[i], null
            ));
        }

        Collections.shuffle(result); //随机打乱
        return result;
    }

    @PostMapping("/q4")
    @ResponseBody
    public List<QuestionOneVo> test4() {
        String[] questionArr = {"终端产品", "外部设备", "光缆"
                , "闪存", "主机", "超文本链接", "中断信号", "设计，安排，展示"
                , "输出端口", "科学记数法"};
        String[] answerArr = {"End Product", "periphery device", "optical cable"
                , "flash memory", "host computer", "hyper link", "interrupt signal", "lay out"
                , "output port", "scientific notation"};
        List<QuestionOneVo> result = new ArrayList<>();
        for (int i = 0; i < questionArr.length; i++) {
            result.add(new QuestionOneVo(
                    i, questionArr[i], answerArr[i], null
            ));
        }

        Collections.shuffle(result); //随机打乱
        return result;
    }

    @PostMapping("/q5")
    @ResponseBody
    public List<QuestionOneVo> test5() {
        String[] questionArr = {
                "RIP", "DVD", "DBMS", "URL", "BIOS"
                , "PPP ", "TCP ", "ROM ", "AI", "PDA"
                , "DSL", "IoT", "MAC", "AI ", "GUI"};
        String[] answerArr = {
                "Routing Information Protocol"
                , "Digital Video Disc"
                , "Database Management System"
                , "Uniform Resource Locator"
                , "Basic Input Output System"

                , "Point to Point Protocol"
                , "Transfer Control Protocol"
                , "Read-Only Memory"
                , "Artificial Intelligence"
                , "Personal Digital Assistant"

                , "Digital Subscriber Line"
                , "Internet of Things"
                , "Media Access Control"
                , "Artificial Intelligence"
                , "Graphic User Interface"};

        String[] answerArr2 = {
                "路由信息协议"
                , "数字视频光盘"
                , "数据库管理系统"
                , "统一资源定位符"
                , "基本输入输出系统"

                , "点对点协议"
                , "传输控制协议"
                , "只读存储器"
                , "人工智能"
                , "个人数字助理"

                , "数字用户线"
                , "物联网"
                , "媒体访问控制"
                , "人工智能"
                , "图形用户界面"};
        List<QuestionOneVo> result = new ArrayList<>();
        for (int i = 0; i < questionArr.length; i++) {
            result.add(new QuestionOneVo(
                    i, questionArr[i], answerArr[i], answerArr2[i]
            ));
        }

        Collections.shuffle(result); //随机打乱
        return result;
    }

    @PostMapping("/q6")
    @ResponseBody
    public List<QuestionOneVo> test6() {
        String[] questionArr = {
                "To remove (recorded material) from a magnetic tape or other storage medium"
                , "A fireproof wall used as a barrier to prevent the spread of fire."
                , "A list, displayed on a monitor, of options available to a computer user."
                , " A minute slice of a semiconducting material, such as silicon or germanium, doped and otherwise processed to have specified electrical characteristics, especially before it is developed into an electronic component or integrated circuit."
                , "The even or odd quality of the number of 1's or 0's in a binary code, often used to determine the integrity of data especially after transmission. "
        };
        String[] answerArr = {"erase", "firewall", "menu"
                , "chip", "parity"};


        List<QuestionOneVo> result = new ArrayList<>();
        for (int i = 0; i < questionArr.length; i++) {
            result.add(new QuestionOneVo(
                    i, questionArr[i], answerArr[i], null
            ));
        }

        Collections.shuffle(result); //随机打乱
        return result;
    }

    @PostMapping("/q7")
    @ResponseBody
    public List<QuestionOneVo> test7() {
        String[] questionArr = {
                "A general-purpose computer has four main sections. They are the arithmetic and logic unit (ALU), the control unit, the memory, and the input and output devices, collectively termed I/O. They are interconnected by busses, often made of groups of wires. "
                , "A network interface card typically provides a physical connection between a host and a network or networks, as well as providing media access control (MAC) functions that allow the host to access the network or networks."
                , "A computer network is composed of multiple computers connected together using a telecommunication system for the purpose of sharing data, resources and communication. "
                , "Unauthorized intruders may try to use these to gain illegal access to your system. You should patch these flaws often to help keep your computer system secure."
                , "The advantage of a machine with absolute access is that it is extremely convenient to use. Because it's simply there, and will do whatever you tell it, without questions, authorization, passwords, or any other mechanism. No, this isn't terribly practical"
                , "A key component common to all CPUs is the program counter, a special memory cell that keeps track of which location in memory the next instruction is to be read from."
                , "The NIC accesses an Ethernet using a unique media access control (MAC) address allocated in a manufacturing stage while a host has its own Internet Protocol (IP) address corresponding to a hostname."
                , "System software helps run the computer hardware and computer system. It includes operating systems, device drivers, diagnostic tools, servers, windowing systems, utilities and more."
                , "An operating system that manages a group of independent computers and makes them appear to be a single computer is known as a distributed operating system."
                , "Unauthorized access is a very high-level term that can refer to a number of different sorts of attacks. The goal of these attacks is to access some resource that your machine should not provide the attacker."
        };
        String[] answerArr = {"通用计算机有四个主要部分。它们是算术和逻辑单元(ALU)、控制单元、存储器和输入和输出设备，统称为I/O。它们通过总线相互连接，通常由一组电线组成。"
                , "网络接口卡通常提供主机和一个或多个网络之间的物理连接，并提供允许主机访问一个或多个网络的媒体访问控制(MAC)功能"
                , "计算机网络是由多台计算机通过电信系统连接在一起，以实现数据、资源和通信的共享。"
                , "未经授权的入侵者可能试图使用这些来非法访问您的系统。你应该经常修补这些缺陷，以帮助保持你的计算机系统的安全。"
                , "具有绝对权限的机器的优点是使用非常方便。因为它就在那里，可以做任何您告诉它的事情，无需提问、授权、密码或任何其他机制。不，这不是很实际"
                , "所有cpu共用的一个关键部件是程序计数器，它是一个特殊的存储单元，用于跟踪下一条指令在内存中的位置。"
                , "网卡使用在制造阶段分配的唯一的媒体访问控制(MAC)地址访问以太网，而主机拥有与主机名相对应的自己的互联网协议(IP)地址。"
                , "系统软件帮助运行计算机硬件和计算机系统。它包括操作系统、设备驱动程序、诊断工具、服务器、窗口系统、实用程序等。"
                , "一个操作系统管理一组独立的计算机，并使它们看起来像一台计算机被称为分布式操作系统。"
                , "未经授权的访问是一个非常高级的术语，可以指多种不同类型的攻击。这些攻击的目标是访问您的机器不应该提供给攻击者的某些资源。"
        };


        List<QuestionOneVo> result = new ArrayList<>();
        for (int i = 0; i < questionArr.length; i++) {
            result.add(new QuestionOneVo(
                    i, questionArr[i], answerArr[i], null
            ));
        }

        Collections.shuffle(result); //随机打乱
        return result;
    }

    @PostMapping("/q8")
    @ResponseBody
    public List<QuestionOneVo> test8() {
        String[] questionArr = {
                "计算机做的每件事都是由CPU管理的。"
                , "通过使用键盘上的方向键移动光标。"
                , "实际上，一个视窗管理器可以被看作是命令行操作系统的图形用户界面"
                , "没有什么能比计算机更好地体现现代生活"
                , "网桥路由器是网桥和路由器的结合。"
                , "常用的内存有RAM、ROM和闪存几种"
                , "总线形拓扑通常用同轴电缆实现。"
                , "计算机芯片主要负责执行指令。"
                , "在计算机屏幕上，文件夹通常看上去像黄色或蓝色的纸文件夹。"
                , "通常高级语言都可以被解释或编译。"
                , "超文本传输协议是浏览器自己的协议，一般用于传递HTML格式的文件。"
                , "防火墙只是一组组件，它们共同构成了两个网络之间的屏障。"
                , "ALU可以执行的两类运算是算术和逻辑。"
                , "统一资源定位符基本上就是赋给浏览器的一个文件的地址。"
                , "从因特网用户的观点看，下载文件是从另一个计算机（或从另一个计算机的网页）上请求它并接收它。"
        };
        String[] answerArr = {"Everything that a computer does is overseen by the CPU."
                , "Move the cursor by using the arrow keys on the keyboard."
                , "In fact, a window manager can be thought of as a GUI for a CLI OS."
                , "Nothing epitomizes modern life better than the computer."
                , "A brouter is a network bridge combined with a router."
                , "The most common types of memory are RAM, ROM, and flash."
                , "A bus topology is norm  ally implemented with coaxial cable."
                , "Computer chips are mainly responsible for executing instructions."
                , "On the computer screen, folders usually look like yellow or blue paper folders."
                , "In general, higher-level languages can be either interpreted or compiled."
                , "Hypertext Transfer Protocol (HTTP) is the browser's own protocol and is typically used to transfer HTML files."
                , "A firewall is just a set of components that together form a barrier between two networks."
                , "The two types of operations that the ALU can perform are arithmetic and logic."
                , "Uniform resource locators are basically the address of a file assigned to the browser."
                , "From an Internet user's point of view, downloading a file is requesting it from another computer (or from a Web page on another computer) and receiving it."
        };


        List<QuestionOneVo> result = new ArrayList<>();
        for (int i = 0; i < questionArr.length; i++) {
            result.add(new QuestionOneVo(
                    i, questionArr[i], answerArr[i], null
            ));
        }

        Collections.shuffle(result); //随机打乱
        return result;
    }

    @PostMapping("/q9")
    @ResponseBody
    public List<QuestionOneVo> test9() {
        String[] questionArr = {
                ""
                , ""
                , ""
                , ""
                , ""
                , ""
                , ""
                , ""
                , ""
                , ""

        };
        String[] answerArr = {
                "more"
                , "LAN"
                , "Ethernet"
                , "address"
                , "offer"
                , "destination"
                , "consults"
                , "another"
                , "networks"
                , "examines"
        };


        List<QuestionOneVo> result = new ArrayList<>();
        for (int i = 0; i < questionArr.length; i++) {
            result.add(new QuestionOneVo(
                    i, questionArr[i], answerArr[i], null
            ));
        }

        Collections.shuffle(result); //随机打乱
        return result;
    }

    @PostMapping("/doFeedback")
    @ResponseBody
    public String test10(String desc) {
        Feedback feedback = new Feedback(null, desc, new Date());
        feedbackService.addFeedback(feedback);
        return "200";
    }
}
